import type { LoginResult } from '@/types/member'
import { http } from '@/utils/http'

type LoginWxMinParams = {
  code: string
  encryptedData?: string
  iv?: string
}
/**
 * 小程序登录
 * @param data 请求参数
 */
export const postLoginWxMinAPI = (data: any) => {
  return http<any>({
    method: 'POST',
    header: { 'Content-Type': 'application/x-www-form-urlencoded' },
    url: '/api/auth/login.php',
    data,
  })
}
export const getuserinfo = (data: any) => {
  return http<any>({
    method: 'POST',
    header: { 'Content-Type': 'application/x-www-form-urlencoded' },
    url: '/api/user/get_user_info.php',
    data,
  })
}
export const getTrashcanDetails = (data: any) => {
  return http<any>({
    method: 'POST',
    header: { 'Content-Type': 'application/x-www-form-urlencoded' },
    url: '/api/trashcan/get_trashcan_details.php',
    data,
  })
}

export const computerorder = (data: any) => {
  return http<any>({
    method: 'POST',
    header: { 'Content-Type': 'application/x-www-form-urlencoded' },
    url: '/api/workers/complete_order.php',
    data,
  })
}
export const postgzryRegister = (data: any) => {
  return http<any>({
    method: 'POST',
    header: { 'Content-Type': 'application/x-www-form-urlencoded' },
    url: '/api/workers/register_worker.php',
    data,
  })
}
export const addtrashcan = (data: any) => {
  return http<any>({
    method: 'POST',
    header: { 'Content-Type': 'application/x-www-form-urlencoded' },
    url: '/api/trashcan/add_trashcan.php',
    data,
  })
}
export const createorder = (data: any) => {
  return http<any>({
    method: 'POST',
    header: { 'Content-Type': 'application/x-www-form-urlencoded' },
    url: '/api/order/create_order.php',
    data,
  })
}
export const bindtrashcan = (data: any) => {
  return http<any>({
    method: 'POST',
    header: { 'Content-Type': 'application/x-www-form-urlencoded' },
    url: '/api/trashcan/bind_trashcan.php',
    data,
  })
}
export const getuserbalance = (data: any) => {
  return http<any>({
    method: 'POST',
    header: { 'Content-Type': 'application/x-www-form-urlencoded' },
    url: '/api/user/get_user_balance.php',
    data,
  })
}
export const getorders = (data: any) => {
  return http<any>({
    method: 'POST',
    header: { 'Content-Type': 'application/x-www-form-urlencoded' },
    url: '/api/order/get_orders.php',
    data,
  })
}
export const getpending = (data: any) => {
  return http<any>({
    method: 'POST',
    header: { 'Content-Type': 'application/x-www-form-urlencoded' },
    url: '/api/order/get_pending_payments.php',
    data,
  })
}
export const addorderaddress = (data: any) => {
  return http<any>({
    method: 'POST',
    header: { 'Content-Type': 'application/x-www-form-urlencoded' },
    url: '/api/order/add_order_address.php',
    data,
  })
}
export const payorder = (data: any) => {
  return http<any>({
    method: 'POST',
    header: { 'Content-Type': 'application/x-www-form-urlencoded' },
    url: '/api/payment/pay_order.php',
    data,
  })
}
export const getorderdetails = (data: any) => {
  return http<any>({
    method: 'POST',
    header: { 'Content-Type': 'application/x-www-form-urlencoded' },
    url: '/api/order/get_order_details.php',
    data,
  })
}
export const getalltrashcans = (data: any) => {
  return http<any>({
    method: 'GET',
    header: { 'Content-Type': 'application/x-www-form-urlencoded' },
    url: '/api/trashcan/get_all_trashcans.php',
    data,
  })
}
export const getpendingorders = (data: any) => {
  return http<any>({
    method: 'GET',
    header: { 'Content-Type': 'application/x-www-form-urlencoded' },
    url: '/api/order/get_pending_orders.php',
    data,
  })
}
export const acceptorder = (data: any) => {
  return http<any>({
    method: 'POST',
    header: { 'Content-Type': 'application/x-www-form-urlencoded' },
    url: '/api/workers/accept_order.php',
    data,
  })
}
export const getworkerorders = (data: any) => {
  return http<any>({
    method: 'POST',
    header: { 'Content-Type': 'application/x-www-form-urlencoded' },
    url: '/api/workers/get_worker_orders.php',
    data,
  })
}

/**
 * 小程序注册
 * @param data 请求参数
 */
export const postRegister = (data: any) => {
  return http<any>({
    method: 'POST',
    header: { 'Content-Type': 'application/x-www-form-urlencoded' },
    url: '/api/auth/register.php',
    data,
  })
}
export const getBainhao = (data: any) => {
  return http<any>({
    method: 'GET',
    header: { 'Content-Type': 'application/x-www-form-urlencoded' },
    url: '/api/trashcan/get_all_trashcans.php',
    data,
  })
}

/**
 * 小程序检测
 * @param data 请求参数
 */
export const isworker = (data: any) => {
  return http<any>({
    method: 'POST',
    header: { 'Content-Type': 'application/x-www-form-urlencoded' },
    url: '/api/user/is_worker.php',
    data,
  })
}
/**
 * 小程序登录_内测版
 * @param phoneNumber 模拟手机号码
 */
export const postLoginWxMinSimpleAPI = (phoneNumber: string) => {
  return http<LoginResult>({
    method: 'POST',
    url: '/login/wxMin/simple',
    data: {
      phoneNumber,
    },
  })
}

type LoginParams = {
  account: string
  password: string
}
/**
 * 传统登录-用户名+密码
 * @param data 请求参数
 */
export const postLoginAPI = (data: LoginParams) => {
  return http<LoginResult>({
    method: 'POST',
    url: '/login',
    data,
  })
}
